
//check if page contains video tag.
var playing_c = true;
var dontplay = false;
if(document.getElementsByTagName("video").length > 0)
{
	var _videos = document.getElementsByTagName("video");
	for(var i = 0, _video; _video = _videos[i]; i++){

		_video.addEventListener("play", function(e){ if (playing_c == true) { chrome.extension.sendRequest({}, function(response) {}); if(dontplay != true) { dontplay = true; this.play();  } } else {  dontplay = true; this.play(); } }, false);
		_video.addEventListener("pause", function(e){ playing_c = false; }, false);
	}
}else {
//  Do nothing
}

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
 var videos = document.getElementsByTagName("video");
 if (request.action == "pauseVideo")
  for (var i = 0, video; video = videos[i]; i++)
	video.pause();
 else {
  //no action necessary here!
 }
 sendResponse({}); // Send nothing..
});
